const sockjs = require("sockjs");

const sockjs_opts = {
  prefix: "/echo"
};

const sockjs_echo = sockjs.createServer(sockjs_opts);

sockjs_echo.on("connection", (conn: any) => {
  conn.on("data", (msg: string) => conn.write(msg));
  setInterval(() => {
    conn.write(new Date().getTime());
  }, 500);
});

export class Socket {
  public static init(server: any) {
    return sockjs_echo.installHandlers(server);
  }
}
